package com.web.kdl.controller.maDataReport;

import com.web.kdl.common.result.CommonResult;
import com.web.kdl.common.result.CursorPageResult;
import com.web.kdl.entity.maDataReport.DataReport;
import com.web.kdl.pojo.form.DataReportForm;
import com.web.kdl.service.excel.ExcelService;
import com.web.kdl.service.maDataReport.DataReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class DataReportController {
    @Autowired
    DataReportService dataReportService;
    @Autowired
    ExcelService excelService;

    //获取一个时间节点的所有飞轮的数据信息
    @PostMapping("/getAllDataPort")
    @ResponseBody
    public CommonResult<List<DataReport>> getAllDataPort(){
        List<DataReport> alldataReport = dataReportService.getAlldataReport();
        return CommonResult.success(alldataReport);
    }

    //获取查询的一个设备的数据信息
    @PostMapping("/getDataReport")
    @ResponseBody
    public CommonResult<List<Map<String, Object>>>getDataReport(@RequestBody DataReportForm dataReportForm){
        List<Map<String, Object>> dataReport = dataReportService.getDataReport(dataReportForm);
        return CommonResult.success(dataReport);
    }
    @PostMapping("/getDataReportPage")
    @ResponseBody
    public CommonResult< CursorPageResult<DataReport> >getDataReportPage(@RequestBody DataReportForm dataReportForm){
        CursorPageResult<DataReport> dataReportPage = dataReportService.getDataReportPage(dataReportForm);
        return CommonResult.success(dataReportPage);
    }


    //获取 父子设备数据信息
    @PostMapping("/getDataReportByParent")
    @ResponseBody
    public CommonResult getDataReportByParent(){
        return dataReportService.getDataReportByParent();
    }
    
    /**
     * 提交导出任务（异步）
     */
    @PostMapping("/submitExportTask")
    @ResponseBody
    public CommonResult submitExportTask(@RequestBody DataReportForm dataReportForm){
        return dataReportService.submitExportTask(dataReportForm);
    }
    
    /**
     * 查询导出任务状态
     */
    @PostMapping("/queryExportTask")
    @ResponseBody
    public CommonResult queryExportTask(@RequestBody Map<String, String> params){
        String taskId = params.get("taskId");
        return excelService.queryExportTask(taskId);
    }
}
